package com.stillalive.springaop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@Aspect
public class MyAspectRun {
    // 针对自定义注解生效（使用这个注解的位置）
    @Around("@annotation(com.stillalive.springaop.aspect.MyAspect)")
    public Object recordTime(ProceedingJoinPoint pjp){
        log.info("目标方法执行前....");
        // 执行目标方法
        Object result = null;
        try {
            result = pjp.proceed();
        }
        catch (Throwable e) {
            log.error("do Around throws exceptions...");
        }
        log.info("目标方法执行后....");
        return result;
    }
}
